package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.Collections;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class TotalingSumInArrayList {
	public static void main(String[] args) {
		Number[] numbers = {1, 2.4, 3, 4.1};
		ArrayList<Number> numberList = new ArrayList<>();

		Collections.addAll(numberList, numbers);

		System.out.printf("ArrayList 包含的元素: %s%n", numberList);
		System.out.printf("ArrayList 总和: %.1f%n", sum(numberList));
	}

	private static double sum(ArrayList<Number> list) {
		double total = 0;
		for (Number element : list)
			total += element.doubleValue();

		return total;
	}
}
